<?php

use yii\db\Migration;

class m180319_095200_after_mechanic_settlement extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->addColumn('{{%mechanic_settlement}}', 'year', $this->string(50)->defaultValue(null)->comment('结算年份'));
            $this->addColumn('{{%mechanic_settlement}}', 'month', $this->string(50)->defaultValue(null)->comment('结算月份'));
            $this->addColumn('{{%mechanic_settlement}}', 'updated_at', $this->integer()->defaultValue(0)->comment('修改时间'));
            $this->addColumn('{{%mechanic_settlement}}', 'subsidy_money', $this->decimal(10,2)->defaultValue(0)->comment('补贴金额'));
            $this->addColumn('{{%mechanic_settlement}}', 'total', $this->decimal(10,2)->defaultValue(0)->comment('总金额'));
            $this->addColumn('{{%mechanic_settlement}}', 'pay_status', $this->smallInteger(2)->defaultValue(0)->comment('付款状态（0 未付款 1 已付款）'));
            $this->alterColumn('{{%mechanic_settlement}}', 'status', $this->smallInteger(3)->defaultValue(10)->comment('状态 10 教务生成结算数据  11 教服合适结算数据 12 机构负责人审核数据 13 财务审核数据'));
            $this->renameColumn('{{%mechanic_settlement_relation}}', 'mechanic_subsidy_divided_id', 'checkcount_id');
            $this->alterColumn('{{%mechanic_settlement_relation}}', 'checkcount_id', $this->integer()->defaultValue(0)->comment('课消统计id'));
        }

    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropColumn('{{%mechanic_settlement}}', 'year');
            $this->dropColumn('{{%mechanic_settlement}}', 'month');
        }
    }
}
